<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../header.jsp">
<jsp:param value="部门管理-子部门" name="title"/>
</jsp:include>
<link href="static/css/total.css" rel="stylesheet" type="text/css">
<link href="static/css/teacher.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	$(function() {
		$('.selection.dropdown').dropdown();
		$("div.checkbox").checkbox();
		var checkAll = $("#checkAll");
		var itemCheck = $(".item-check");

		checkAll.on("change", function() {
			//获取全选框选中状态
			itemCheck.prop("checked", this.checked)
		});

		itemCheck.on("change", function() {
			//判断判断选中的个数是否和所有存在个数一样
			var checkeds = $(".item-check:checked");
			//修改checkAll的checked属性
			checkAll.prop("checked", checkeds.length == itemCheck.length);
		});
		$('#delete').on('click', function() {
			//获取所有选中
			var checkeds = $(".item-check:checked");
			if (checkeds.length && confirm("确认要删除所有选中行吗？")) {
				//获取所有选择的id
				var ids = [];
				checkeds.each(function() {
					ids.push(this.value);
				});
				location.replace("dept/sondept/delt?id="+"${parentDept.id}"+"&id="+ ids.join("&id="));
				alert("id="+"${parentDept.id}"+"&id="+ ids.join("&id="));
			}
		});
	});
	
	function dow(){
		$('.ui.labeled.icon.sidebar')
			.sidebar('setting', 'transition','overlay')
			.sidebar('toggle');
	}
</script>
</head>
<body>
	<jsp:include page="../menu/manage_menu.jsp"></jsp:include>
	<div class="teacher-content" style="margin-right: 100px;">
		<div>当前部门：<a href="dept/form?id=${parentDept.id}">${parentDept.deptName}</a></div>
		
		
		<span class="erroList">
			<c:forEach items="${cantBeDeleDeptList}" var="dept">
			<span>${dept.deptName}</span>
			</c:forEach>
				${deleErro}
		</span>
		<table class="ui celled striped table dept-table">
			<thead>
				<tr>
					<th colspan="6">部门列表</th>
				</tr>
				<tr>
					<th colspan="6">
						<div class="ui buttons btns" style="float:left">
							<a href="dept/sondept/form?pid=${parentDept.id}" class="ui button"  style="color:#fff; background: #666;"> 
							<i class="icon user"></i>
								创建子部门
							</a>
							<button class="ui button" id="delete" onclick="del()">
								<i class="icon trash"></i> 删除部门
							</button>
						</div>
						<div class="searcherSon" style="float:right;">
							<form class="find">
								<div class="ui form">
									<div class="fields">
										<div class="field">
											 <input type="text" name="deptName" value="${param.deptName }" placeholder="输入部门搜索">
										</div>
										<div class="field">
											 <input type="text" name="deptManager" placeholder="输入经理搜索"
												value="${param.deptManager }">
										</div>
										<input type="hidden" name="id" value="${parentDept.id }">
										<div class="field">
											<button class="ui submit button">检索</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td class="collapsing">
						<div class="ui checkbox">
							<input type="checkbox" id="checkAll">
						</div>
					</td>
					<td class="collapsing">部门名称</td>
					<td class="collapsing">部门经理</td>
					<td class="collapsing">上属部门</td>
					<td class="collapsing">创建时间</td>
					<td>&nbsp;</td>
				</tr>
				<c:forEach items="${deptList }" var="dept">

					<tr>
						<td class="collapsing">
							<div class="ui checkbox">
								<input class="item-check" type="checkbox" value="${dept.id }">
							</div>
						</td>
						<td class="collapsing"><a href="dept/sondept/form?pid=${parentDept.id}&id=${dept.id}">${dept.deptName}</a></td>
						<td class="collapsing">${empty dept.deptManager ?"无 ":dept.deptManager}</td>
						<td class="collapsing">${empty dept.parentDeptName?"无":dept.parentDeptName}</td>
						<td class="collapsing"><fmt:formatDate
								value="${dept.createData}" type="both" /></td>
						<td class="collapsing"><a onclick="return confirm('确认删除？')"
							class="ui label" href="dept/sondept/delt?id=${parentDept.id}&id=${dept.id}"  style="color:#fff; background: #666;">
							 <i class="icon trash"></i> 删除
						</a> <a class="ui label" href="dept/son?id=${dept.id}">子部门 </a></td>
					</tr>
				</c:forEach>
				<c:if test="${empty deptList}">
					<tr>
						<td style="text-align: center;" colspan="6">暂无记录</td>
					</tr>
				</c:if>
			</tbody>
		</table>
		<c:if test="${totalPage > 1 }">
			<div class="page">
				<a <c:if test="${page!=1}">href="dept?page=1${queryString}"</c:if>
					class="${page == 1?'disable':''}" style="color:#666"><i class="fast backward icon"></i>首页
				</a>
				<a <c:if test="${page!=1}">href="dept?page=${page-1}${queryString}"</c:if>
					class="${page == 1?'disable':''}" style="color:#666"><i class="backward icon"></i>下一页
				</a>
				<a <c:if test="${page!=totalPage}">href="dept?page=${page+1 }${queryString}"</c:if>
					class="${page == totalPage?'disable':''}" style="color:#666">上一页<i class="forward icon"></i>
				</a>
				<a <c:if test="${page!=totalPage}">href="dept?page=${totalPage }${queryString}"</c:if>
					class="${page == totalPage?'disable':''}" style="color:#666">尾页<i class="fast forward icon"></i>
				</a>
				<span style="float:right">${page}/${totalPage }</span>
					
			</div>
		</c:if>
	</div>
</body>
</html>